package com.yuanfeng.base.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.yuanfeng.base.dto.*;
import com.yuanfeng.base.entity.BaseFloorAdpageEntity;
import com.yuanfeng.base.mapper.*;
import com.yuanfeng.base.service.WebIndexService;
import com.yuanfeng.base.vo.*;
import com.yuanfeng.base.vo.index.*;
import com.yuanfeng.commoms.constant.CommonStatusEnum;
import com.yuanfeng.commoms.constant.CommonType;
import com.yuanfeng.commoms.constant.RedisConstants;
import com.yuanfeng.commoms.dto.goods.MobConfigGoodsDTO;
import com.yuanfeng.commoms.dto.goods.WebGoodsListQueryDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.Json.JSONSerializer;
import com.yuanfeng.commoms.util.Json.JsonUtils;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.RedisPrefixUtils;
import com.yuanfeng.commoms.util.RedisUtil;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.util.excel.Constants;
import com.yuanfeng.commoms.vo.base.DealerApplyInfoVO;
import com.yuanfeng.commoms.vo.goods.GoodsCatVO;
import com.yuanfeng.commoms.vo.goods.GoodsIdsVO;
import com.yuanfeng.commoms.vo.goods.SecordNameListVO;
import com.yuanfeng.commoms.vo.goodscat.GoodsCatSearchChildVO;
import com.yuanfeng.commoms.vo.goodscat.WebCatMenuVO;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName WebIndexServiceImpl
 * @Description pc首页装修
 * @Author cyp
 * @Date 2023/5/24 9:18
 * @Version 1.0
 */
@Service
public class WebIndexServiceImpl implements WebIndexService {


    @Autowired
    private BaseSysConfigsMapper baseSysConfigsMapper;
    @Autowired
    private BaseArticleGroupMapper baseArticleGroupMapper;
    @Autowired
    private BaseArticleBaseMapper baseArticleBaseMapper;
    @Autowired
    private BaseFoodExhibitionHallMapper baseFoodExhibitionHallMapper;
    @Autowired
    private WebIndexMapper webIndexMapper;
    @Autowired
    private BaseFloorAdpageMapper baseFloorAdpageMapper;
    @Autowired
    private BaseSystemPlatformNavMapper baseSystemPlatformNavMapper;
    @Autowired
    private BasePcIndexConfigMapper basePcIndexConfigMapper;
    @Autowired
    private BaseDealerApplyInfoMapper baseDealerApplyInfoMapper;
    @Autowired
    private BasePcIndexConfigServiceImpl basePcIndexConfigService;

    @Override
    public ResponseResult queryAllAdpageFloor() {

        List<BaseFloorAdpageEntity> entityList = baseFloorAdpageMapper.selectList(new LambdaQueryWrapper<BaseFloorAdpageEntity>()
                .eq(BaseFloorAdpageEntity::getFloorType, CommonType.storeType.SELLER_STORE.getCode()));


        /**
         * 封装数据
         */
        List<MerchantFloorAdpageVO> allFloorAdpages = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(entityList)) {
            allFloorAdpages = entityList.stream().map(entity -> {
                MerchantFloorAdpageVO catResult = new MerchantFloorAdpageVO();

                BeanUtils.copyProperties(entity, catResult);
                return catResult;
            }).collect(Collectors.toList());
        }

        for (MerchantFloorAdpageVO allFloorAdpage : allFloorAdpages) {
            // 获取楼层名称
            WebFloorAdpageNameDTO floorAdpageNameNew = JsonUtils.string2Obj(allFloorAdpage.getFloorAdpageName(),
                    WebFloorAdpageNameDTO.class);
            allFloorAdpage.setFloorAdpageNameNew(floorAdpageNameNew);
            // 获取轮播图
            List<Integer> goodsIdList2 = JsonUtils.StringToList2(allFloorAdpage.getLeftAdpageBanner());
            List<GoodsIdsQueryListVO> adpageBannerList = webIndexMapper.selectByGoodIds(goodsIdList2);
            allFloorAdpage.setAdpageBannerList(adpageBannerList);
            // 获取左侧广告
            List<PlatformLeftAdpageNavDTO> leftAdpageNavList = JsonUtils.string2Obj(allFloorAdpage.getLeftAdpageNav(),
                    List.class, PlatformLeftAdpageNavDTO.class);
            for (PlatformLeftAdpageNavDTO platformLeftAdpageNav : leftAdpageNavList) {
                String leftAdpageNavUrl = String.valueOf(platformLeftAdpageNav.getLeftAdpageNavUrl());
                if (StringUtils.isNotEmpty(leftAdpageNavUrl)) {
                    Map urlMap = JSON.parseObject(leftAdpageNavUrl, Map.class);
                    if (platformLeftAdpageNav.getOpType() != null) {
                        //封装商品信息
                        if (platformLeftAdpageNav.getOpType().equals(2) && null != urlMap.get("commonId")) {
                            String commonId = String.valueOf(urlMap.get("commonId"));
                            if (StringUtils.isNotEmpty(commonId)) {
                                String commonName = webIndexMapper.selectCommonNameId(Integer.valueOf(commonId));
                                platformLeftAdpageNav.setCommonName(commonName);
                            }
                            //封装店铺信息
                        } else if (platformLeftAdpageNav.getOpType().equals(4) && null != urlMap.get("shopId")) {
                            String shopId = String.valueOf(urlMap.get("shopId"));
                            if (StringUtils.isNotEmpty(shopId)) {
                                String shopName = webIndexMapper.selectByShopNameId(Integer.valueOf(shopId));
                                platformLeftAdpageNav.setShopName(shopName);
                            }
                            //封装分类信息
                        } else if (platformLeftAdpageNav.getOpType().equals(6) && null != urlMap.get("catId")) {
                            String catId = String.valueOf(urlMap.get("catId"));
                            if (StringUtils.isNotEmpty(catId)) {
                                String catName = webIndexMapper.selectByCatNameString(Integer.valueOf(catId));
                                platformLeftAdpageNav.setCatName(catName);
                            }
                        }
                    }
                }
            }
            allFloorAdpage.setLeftAdpageNavList(leftAdpageNavList);
            // 获取右侧热门推荐
            PlatformRightAdpageNavDTO rightRec = JsonUtils.string2Obj(allFloorAdpage.getRightHotRecommend(),
                    PlatformRightAdpageNavDTO.class);
            allFloorAdpage.setRightRec(rightRec);
            // 设置的商品数量
            if(StringUtils.isNotEmpty(rightRec.getRightAdpageNavGoodsId())) {
                List<Integer> rightAdpageNavGoodsIds = JsonUtils.StringToList2(rightRec.getRightAdpageNavGoodsId());

                List<GoodsIdsVO> rightRecGoodsList = new ArrayList<>();
                MobConfigGoodsVO query = new MobConfigGoodsVO();
                List<WebCatMenuVO> allMenu = null;
                // 获取所有的子分类
                if (null == allMenu) {
                    allMenu = webIndexMapper.selectAllCat2();
                }
                List<Integer> catIds = getMenuList(allMenu, floorAdpageNameNew.getCatId());
                query.setCatIds(catIds);
                query.setGoodsIdList(rightAdpageNavGoodsIds);
                query.setGoodsNum(8 - rightRecGoodsList.size());
                List<Integer> goodsVarList =query.getGoodsIdList();
                for (Integer goodsId :goodsVarList){
                    GoodsIdsVO param = webIndexMapper.newSelectWebFloorMobConfig(goodsId);
                    if (param !=null){
                        rightRecGoodsList.add(param);
                    }
                }
                allFloorAdpage.setRightRecGoodsList(rightRecGoodsList);
            }
            // 获取右侧分类广告
            allFloorAdpage.setRightAdpageNavList(JsonUtils.string2Obj(allFloorAdpage.getRightAdpageNav(), List.class,
                    WebFloorAdpageNameVO.class));
        }
        return ResponseResult.success(allFloorAdpages);
    }

    /**
     * 获取商品分类所有的子分类
     *
     * @param allMenu
     * @param catId
     * @return
     */
    public List<Integer> getMenuList(List<WebCatMenuVO> allMenu, Integer catId) {
        List<Integer> allChildCatIds = Lists.newArrayList();

        if (!org.springframework.util.CollectionUtils.isEmpty(allMenu)) {
            for (WebCatMenuVO catMenu : allMenu) {
                if (catMenu.getCatId().equals(catId)) {
                    allChildCatIds.add(catId);
                    getChild(allMenu, catMenu.getCatId(), allChildCatIds);
                }

            }
        }
        return allChildCatIds;

    }
    /**
     * 找出子菜单
     *
     * @return
     */
    private List<Integer> getChild(List<WebCatMenuVO> allMenu, Integer parentId, List<Integer> allChildCatIds) {

        List<Integer> childList = Lists.newArrayList();
        for (WebCatMenuVO catMenu : allMenu) {
            if (catMenu.getCatParentId().equals(parentId)) {
                allChildCatIds.add(catMenu.getCatId());
                childList.add(catMenu.getCatId());
                getChild(allMenu, catMenu.getCatId(), allChildCatIds);
            }
        }

        if (org.springframework.util.CollectionUtils.isEmpty(childList)) {
            return null;
        }

        return allChildCatIds;
    }

    @Override
    public ResponseResult queryIndex(Integer integralType) {
        WebIndexQueryVO result = new WebIndexQueryVO();

        // 查询首页导航
        List<WebSystemPlatformNavVO> platformNav = baseSystemPlatformNavMapper.selectPlatformNav(CommonType.ShopType.COMMON_SHOP.getCode());
        // 轮播
        WebSystemConfigQueryDTO param = new WebSystemConfigQueryDTO();
        param.setConfigType("index_slider");
        List<WebSystemConfigQueryVO> indexSlides = baseSysConfigsMapper.selectByParam(param);
        // 轮播下广告
        WebSystemConfigQueryDTO adParam = new WebSystemConfigQueryDTO();
        adParam.setConfigType("pc_index_ad");
        List<WebSystemConfigQueryVO> indexSlidesAds =baseSysConfigsMapper.selectByParam(adParam);

        // 查询一级分类
        WebGoodsCatQueryDTO catQueryParam = new WebGoodsCatQueryDTO();
        catQueryParam.setCatId(0);
        if(null ==  integralType){
            catQueryParam.setIsIntegralGoods(2);
        }else{
            catQueryParam.setIsIntegralGoods(integralType);
        }
        List<GoodsCatVO> goodsCats = webIndexMapper.selectByParam(catQueryParam);
        for (GoodsCatVO goodsCatResult : goodsCats) {
            List<SecordNameListVO> secordNameList = webIndexMapper.selectByCatParentId(goodsCatResult.getCatId());
            goodsCatResult.setSecordNameList(secordNameList);
        }

        // 热搜词
        List<WabSystemConfigHallVO> slides = baseSysConfigsMapper.selectByConfigTypesearch("search");
        String hotWordsStr = slides.get(0).getConfigValue();
        List<String> hotWords = JsonUtils.StringToList3(hotWordsStr);

        // 疯狂快报
        WebIndexArticleGroupVO articleGroup = null;
        List<WebIndexArticleGroupVO> articleGroups = baseArticleGroupMapper.selectAllGroup();
        for (WebIndexArticleGroupVO articleGroup1 : articleGroups) {
            if(1 == articleGroup1.getArticleGroupSort()){
                articleGroup = baseArticleGroupMapper.selectByArticleGroupId(articleGroup1.getArticleGroupId());
                List<WebArticleBaseNameVO> articleBase = baseArticleBaseMapper.selectByGroupId(articleGroup.getArticleGroupId(), 7);
                articleGroup.setArticletitle2(articleBase);
                break;
            }
        }

        // 地方特产馆
        List<WebIndexSpecialtysHallVO> halls = getSpeciatysHall(param);

        result.setIndexSpecialty(halls);
        result.setPlatformNav(platformNav);
        result.setIndexSlides(indexSlides);
        result.setGoodsCats(goodsCats);
        result.setHotWords(hotWords);
        result.setArticleGroup(articleGroup);
        result.setIndexSlidesAds(indexSlidesAds);
        return ResponseResult.success(result);
    }
    private List<WebIndexSpecialtysHallVO> getSpeciatysHall(WebSystemConfigQueryDTO param) {
        // 地方特产馆
        List<WebIndexSpecialtysHallVO> halls = Lists.newArrayList();

        List<WebIndexSpecialtysHallVO>  specialtysHallList=new ArrayList<>();
        specialtysHallList = baseFoodExhibitionHallMapper.getSpecialCollections();

        for (WebIndexSpecialtysHallVO webIndex : specialtysHallList) {
            if (StringUtils.isNotEmpty(webIndex.getGoodsId())) {
                String[] strArray = webIndex.getGoodsId().split(",");
                List<GoodsIdsQueryVO> goodsList = new ArrayList<>();
                if (strArray.length <= 2) {
                    for (int i = 0; i < strArray.length; i++) {
                        Integer goodsId = Integer.valueOf(strArray[i]);
                        GoodsIdsQueryVO resultList = webIndexMapper.selectGoodsIdList(goodsId);
                        goodsList.add(resultList);
                    }
                } else {
                    for (int i = 0; i < 2; i++) {
                        Integer goodsId = Integer.valueOf(strArray[i]);
                        GoodsIdsQueryVO resultList = webIndexMapper.selectGoodsIdList(goodsId);
                        goodsList.add(resultList);
                    }
                }
                webIndex.setGoodsList(goodsList);
            }
            halls.add(webIndex);

        }
        return halls;
    }

    @Override
    public ResponseResult selectPcIndexConfigAll() {
        //pc首页的天天特价
        List<PcConfigResultVO> result = new ArrayList<>();
        try {
            String pcConfig = RedisUtil.get(RedisPrefixUtils.pcIndexConfig);
           if(null != pcConfig){
               result = JsonUtils.string2Obj(pcConfig,List.class,PcConfigResultVO.class);//从redis中获取
               if(CollectionUtils.isNotEmpty(result)){
                   for (PcConfigResultVO pcConfigResult : result) {
                       if (null !=pcConfigResult.getGoods() && pcConfigResult.getGoods().size()>0){
                           List<PcConfigGoodsVO> goods = new ArrayList<>();//存放商品信息
                           for (PcConfigGoodsVO good : pcConfigResult.getGoods()) {
                               PcConfigGoodsVO pcConfigGoodsParam = webIndexMapper.pcConfigGoods(good.getCommonId());//根据common 查询商品信息
                               if (pcConfigGoodsParam != null){
                                   goods.add(pcConfigGoodsParam);
                               }
                           }
                           pcConfigResult.getGoods().clear();
                           pcConfigResult.getGoods().addAll(goods);
                       }
                   }
                   return ResponseResult.success(result);
               }else{
                   RedisUtil.remove(RedisPrefixUtils.pcIndexConfig);
               }
           }
            GdbPcIndexConfigVO pcIndexConfig = new GdbPcIndexConfigVO();
            List<GdbPcIndexConfigVO> gdbPcIndexConfigs = basePcIndexConfigMapper.selectPcIndexConfig(pcIndexConfig);//查询所有数据 解析
            if(null != gdbPcIndexConfigs && gdbPcIndexConfigs.size() > 0){
                for (GdbPcIndexConfigVO gdbPcIndexConfig : gdbPcIndexConfigs) {
                    PcConfigResultVO pcConfigResult = new PcConfigResultVO();//用与存放 商品 店铺数据
                    pcConfigResult.setPageType(gdbPcIndexConfig.getPageType());
                    pcConfigResult.setPageName(gdbPcIndexConfig.getPageName());
                    pcConfigResult.setPageTitle(gdbPcIndexConfig.getPageTitle());
                    pcConfigResult.setPageTwoTitle(gdbPcIndexConfig.getPageTwoTitle());
                    pcConfigResult.setPageId(gdbPcIndexConfig.getId());
                    pcConfigResult.setPageStart(gdbPcIndexConfig.getPageStart());
                    String data = gdbPcIndexConfig.getPageData();// 获取页面数据
                    if(null != data && "" != data){
                        GdbPcIndexConfigDataVO gdbPcIndexConfigData = JSON.parseObject(data, GdbPcIndexConfigDataVO.class);
                        List<Integer> ids = gdbPcIndexConfigData.getData();
                        if(null != gdbPcIndexConfigData.getType() && 1 == gdbPcIndexConfigData.getType()){//商品
                            List<PcConfigGoodsVO> goods = new ArrayList<>();//存放商品信息
                            if(null != ids){
                                for (Integer id : ids) {
                                    PcConfigGoodsVO pcConfigGoodsParam = webIndexMapper.pcConfigGoods(id);//根据common 查询商品信息
                                    if(null != pcConfigGoodsParam){
                                        goods.add(pcConfigGoodsParam);
                                    }
                                }
                                pcConfigResult.setGoods(goods);
                            }
                        }else if(null != gdbPcIndexConfigData.getType() && 2 == gdbPcIndexConfigData.getType()){//店铺
                            List<PcConfigShopVO> shops = new ArrayList<>();//存放店铺信息
                            if(null != ids){
                                for (Integer id : ids) {
                                    PcConfigShopVO pcConfigShopParam = webIndexMapper.pcConfigShop(id);//根据shopid
                                    if(null != pcConfigShopParam){
                                        if(StringUtils.isEmpty(pcConfigShopParam.getCommonImage())){
                                            String icoShop = baseSysConfigsMapper.selectConfigValue("logo_copywriting_ico_shop");
                                            pcConfigShopParam.setCommonImage(icoShop);
                                        }
                                        shops.add(pcConfigShopParam);
                                    }
                                }
                                pcConfigResult.setShops(shops);
                            }
                        }else if(null != gdbPcIndexConfigData.getType() && 3 == gdbPcIndexConfigData.getType()){//分类
                            PcConfigCatVO pcConfigCatParam = new PcConfigCatVO();
                            pcConfigCatParam.setCatImage(gdbPcIndexConfigData.getImages());
                            if(null != ids){
                                for (Integer id : ids) {
                                    pcConfigCatParam.setCatUrl(String.valueOf(id));
                                }
                            }
                            pcConfigResult.setCat(pcConfigCatParam);
                        }
                    }
                    result.add(pcConfigResult);
                }
                if(null != result){
                    RedisUtil.set(RedisPrefixUtils.pcIndexConfig, JSONSerializer.serialize(result), 60 * 60 * 24);//存入redis
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseResult.success(result);
    }

    @Override
    public ResponseResult queryByGoodsCatId(Integer catId, Integer goodsType, String token) {
        // 获取分类id
        GoodsCatSearchChildVO goodsCatSearchChild = null;
        List<WebCatMenuVO> allMenu = null;
        List<Integer> catIds = null;
        if (null != catId) {
            // 从缓存中获取
            String cacheCatIds = RedisUtil.get(Constants.CACHE_GOODS_WEB_GOODS_LIST_HEADER_PREFIX + "_" + catId );

            if (null != cacheCatIds && !cacheCatIds.equals("")) {
                goodsCatSearchChild = JsonUtils.string2Obj(cacheCatIds, GoodsCatSearchChildVO.class);
                catIds = goodsCatSearchChild.getCatIds();
            } else {
                // 查询所有下级分类
                allMenu = webIndexMapper.selectAllCat2();
                catIds = getMenuList(allMenu, catId);
                goodsCatSearchChild = new GoodsCatSearchChildVO();
                goodsCatSearchChild.setAllMenu(allMenu);
                goodsCatSearchChild.setCatIds(catIds);
                RedisUtil.set(Constants.CACHE_GOODS_WEB_GOODS_LIST_HEADER_PREFIX + "_" + catId ,
                        JsonUtils.toString(goodsCatSearchChild),RedisUtil.EXRP_MONTH);
            }
            catIds.add(catId);
        }
        List<GoodsIdsQueryVO> results = webIndexMapper.selectByCatIds(catIds,goodsType);
        UserInfoVO userInfo = null;
        if(StringUtils.isNotBlank(token)) {
            userInfo = ParseTokenUtils.getUserInfoByToken(token);
        }
        if(null != userInfo && null != goodsType && 2 == goodsType){
            // 获取所有商品店铺信息
            List<Integer> goodsShopIdList = results.stream().map(GoodsIdsQueryVO::getShopId).distinct().collect(Collectors.toList());
            // 查询登录用户已申请经销商成功的店铺id
            List<DealerApplyInfoVO> dealerApplyInfoList = baseDealerApplyInfoMapper.queryDealerApplyListByShop(userInfo.getShopId(),goodsShopIdList);
            if(!org.springframework.util.CollectionUtils.isEmpty(dealerApplyInfoList)) {
                goodsShopIdList = dealerApplyInfoList.stream().map(DealerApplyInfoVO::getSupplierShopId).distinct().collect(Collectors.toList());
                for (GoodsIdsQueryVO goods : results) {
                    // 商品无需申请经销商
                    if (null != goods.getSellCheck() && goods.getSellCheck().intValue() == 2) {
                        goods.setOperateType(goods.getSellDeliver());
                    } else {
                        if (!goodsShopIdList.contains(goods.getShopId())) {
                            goods.setOperateType(CommonType.supplierGoodsStatus.APPLY.getCode());
                        } else {
                            goods.setOperateType(goods.getSellDeliver());
                        }
                    }
                }
            }else{
                for (GoodsIdsQueryVO goods : results) {
                    goods.setOperateType2(goods);
                }
            }
        }
        return ResponseResult.success(results);
    }

    @Override
    public ResponseResult queryAdpageFloorGoods(Map<String, Object> map) {
        UserInfoVO userInfo = null;
        if(null != map.get("token")){
            userInfo = ParseTokenUtils.getUserInfoByToken(map.get("token").toString());
        }
        List<Integer> goodsIds = new ArrayList<>();
        List<GoodsIdsQueryVO> goodsList = new ArrayList<>();
        if(null != userInfo){
            if(null != map.get("goodsIds")){
                goodsIds = (List<Integer>) map.get("goodsIds");
                goodsList = webIndexMapper.selectGoodsByGoodIds(goodsIds);
                // 查询登录用户已申请经销商成功的店铺id
                List<DealerApplyInfoVO> dealerApplyInfoList =  baseDealerApplyInfoMapper.queryDealerApplyListByShop(userInfo.getShopId(),goodsIds);
                if(!org.springframework.util.CollectionUtils.isEmpty(dealerApplyInfoList)) {
                    goodsIds = dealerApplyInfoList.stream().map(DealerApplyInfoVO::getSupplierShopId).distinct().collect(Collectors.toList());
                    for (GoodsIdsQueryVO goods : goodsList) {
                        // 商品无需申请经销商
                        if (null != goods.getSellCheck() && goods.getSellCheck().intValue() == 2) {
                            goods.setOperateType(goods.getSellDeliver());
                        } else {
                            if (!goodsIds.contains(goods.getShopId())) {
                                goods.setOperateType(CommonType.supplierGoodsStatus.APPLY.getCode());
                            } else {
                                goods.setOperateType(goods.getSellDeliver());
                            }
                        }
                    }
                }else{
                    for (GoodsIdsQueryVO goods : goodsList) {
                        goods.setOperateType2(goods);
                    }
                }
            }
        }else{
            if(null != map.get("goodsIds")){
                goodsIds = (List<Integer>) map.get("goodsIds");
                goodsList = webIndexMapper.selectGoodsByGoodIds(goodsIds);
            }
        }
        return ResponseResult.success(goodsList);
    }

    @Override
    public ResponseResult queryItemCat(Integer catParentId,Integer shopId) {
        List<GoodCatsResultVO> result = null;
        if (shopId == null) {
            // 从缓存中查找
//            String redisResult = RedisUtil.get(RedisPrefixUtils.goodsClassify + catParentId);
//            if (null != redisResult && !redisResult.equals("")) {
//                result = JsonUtils.string2Obj(redisResult, List.class, GoodCatsResultVO.class);
//                return ResponseResult.success(result);
//            }

            // 从数据库查询分类
            // 获取分类id
            List<Integer> catIds = null;
            WebGoodsCatQueryDTO param = getChildCatList(catIds, catParentId);

            List<GoodsCatVO> goodsCats = webIndexMapper.selectByParam(param);
            result = Lists.newArrayList();
            // 判断是否是二级分类，是获取三级分类
            if (catParentId != 0) {
                for (GoodsCatVO goodsCat : goodsCats) {
                    GoodCatsResultVO cats = new GoodCatsResultVO();

                    Integer catId = goodsCat.getCatId();
                    param = getChildCatList(catIds, catId);
                    // 获取三级菜单
                    List<GoodsCatVO> threeGoodsCats2 = Lists.newArrayList();

                    List<GoodsCatVO> threeGoodsCats = webIndexMapper.selectByParam(param);
                    cats.setSecordCatId(goodsCat.getCatId());

                    for (GoodsCatVO goodsCatVO : threeGoodsCats) {
                        threeGoodsCats2.add(goodsCatVO);
                    }

                    cats.setGdsCats(threeGoodsCats2);
                    cats.setCatPic(goodsCat.getCatPic());
                    cats.setSecordCatName(goodsCat.getCatName());
                    result.add(cats);

                }
            } else {
                GoodCatsResultVO cats = new GoodCatsResultVO();
                cats.setGdsCats(goodsCats);
                result.add(cats);
            }

            // 存入缓存
            RedisUtil.set(RedisPrefixUtils.goodsClassify + catParentId, JsonUtils.toString(result), RedisUtil.EXRP_MONTH);

        }else{
            //查询店铺自定义的分类
            if (catParentId == 0) {
                List<GoodsCatVO> goodsCatResults = webIndexMapper.selectByShopId1(catParentId, shopId);
                GoodCatsResultVO cats = new GoodCatsResultVO();
                cats.setGdsCats(goodsCatResults);
                result.add(cats);
            }else{
                List<GoodCatsResultVO> goodsCatResults = webIndexMapper.selectByShopId2(catParentId, shopId);
                result.addAll(goodsCatResults);
            }

        }
        return ResponseResult.success(result);
    }
    private WebGoodsCatQueryDTO getChildCatList(List<Integer> catIds, Integer catId) {
        GoodsCatSearchChildVO goodsCatSearchChild;
        List<WebCatMenuVO> allMenu;
        if (null != catId) {
            // 从缓存中获取
            String cacheCatIds = RedisUtil.get(Constants.CACHE_GOODS_WEB_GOODS_LIST_HEADER_PREFIX + "_" + catId);
            // 查询所有下级分类
            allMenu = webIndexMapper.selectAllCat2();
            if (null != cacheCatIds && !cacheCatIds.equals("")) {
                goodsCatSearchChild = JsonUtils.string2Obj(cacheCatIds, GoodsCatSearchChildVO.class);
                catIds = goodsCatSearchChild.getCatIds();
            } else {
                allMenu = webIndexMapper.selectAllCat2();
                catIds = getMenuList(allMenu, catId);
                goodsCatSearchChild = new GoodsCatSearchChildVO();
                goodsCatSearchChild.setAllMenu(allMenu);
                goodsCatSearchChild.setCatIds(catIds);
                RedisUtil.set(Constants.CACHE_GOODS_WEB_GOODS_LIST_HEADER_PREFIX + "_" + catId,
                        JsonUtils.toString(goodsCatSearchChild),RedisUtil.EXRP_MONTH);
            }
        }

        WebGoodsCatQueryDTO param = new WebGoodsCatQueryDTO();
        param.setCatIdList(catIds);
        param.setCatId(catId);
        return param;
    }

    @Override
    public ResponseResult queryPlatformNav() {
        WebPlatformNavResultVO result = new WebPlatformNavResultVO();
        // 查询首页导航
        List<WebSystemPlatformNavVO> platformNav = baseSystemPlatformNavMapper.selectPlatformNav(CommonType.ShopType.COMMON_SHOP.getCode());

        // 热搜词
        List<WabSystemConfigHallVO> slides = baseSysConfigsMapper.selectByConfigTypesearch("search");
        String hotWordsStr = slides.get(0).getConfigValue();
        List<String> hotWords = JsonUtils.StringToList3(hotWordsStr);
        result.setHotWords(hotWords);
        result.setPlatformNav(platformNav);
        return ResponseResult.success(result);
    }

    @Override
    public ResponseResult queryGoodsListHeaderFilter(WebGoodsListQueryDTO param) {
        List<WebCatMenuVO> allMenu = null;
        GoodsCatSearchChildVO goodsCatSearchChild = null;
        List<SecordNameListVO> nextCatIds = null;

        Integer catId = param.getCatId();

        List<Integer> catIds = null;

        if (null != param.getCatId()) {

            // 从缓存中获取
            String cacheCatIds = RedisUtil
                    .get(Constants.CACHE_GOODS_WEB_GOODS_LIST_HEADER_PREFIX + "_" + param.getCatId());
            // 查询所有下级分类
            if (null != cacheCatIds && !cacheCatIds.equals("")) {
                goodsCatSearchChild = JsonUtils.string2Obj(cacheCatIds, GoodsCatSearchChildVO.class);
                catIds = goodsCatSearchChild.getCatIds();
                allMenu = goodsCatSearchChild.getAllMenu();
            } else {
                allMenu = webIndexMapper.selectAllCat2();
                catIds = getMenuList(allMenu, param.getCatId());

                goodsCatSearchChild = new GoodsCatSearchChildVO();
                goodsCatSearchChild.setAllMenu(allMenu);
                goodsCatSearchChild.setCatIds(catIds);
                RedisUtil.set(Constants.CACHE_GOODS_WEB_GOODS_LIST_HEADER_PREFIX + "_" + param.getCatId(),
                        JsonUtils.toString(goodsCatSearchChild),RedisUtil.EXRP_MONTH);
            }

            if (!org.springframework.util.CollectionUtils.isEmpty(catIds)) {
                catIds.add(param.getCatId());
                param.setCatIds(catIds);
                param.setCatId(0);
            }
        }

        // 获取分类列表
        List<WebCatMenuVO> goodsCatsList = getMenuList4(allMenu, catId);

        // 背景图
        WebSystemConfigQueryDTO adParam = new WebSystemConfigQueryDTO();
        adParam.setConfigType("PCGoodsPage");
        List<WebSystemConfigQueryVO> pcGoodsPage =baseSysConfigsMapper.selectByParam(adParam);

        // 推荐商品
        if (null == catId || catId.equals("")) {
            catId = webIndexMapper.selectCatIdByCommonName(param.getCommonName());
            param.setCatId(catId);
        }
        List<GoodsIdsQueryVO> recommendGoodsList = webIndexMapper.selectRecGoods(param);
        if (org.springframework.util.CollectionUtils.isEmpty(recommendGoodsList) || recommendGoodsList.size() != 4) {
            param.setCatId(null);
            recommendGoodsList = webIndexMapper.selectRecGoods(param);
        }

        GoodsListHeaderResultVO result = new GoodsListHeaderResultVO();
        result.setGoodsCatsList(goodsCatsList != null ? goodsCatsList : new ArrayList<WebCatMenuVO>());
        result.setNextCatIds(nextCatIds != null ? nextCatIds : new ArrayList<SecordNameListVO>());
        result.setRecommendGoodsList(
                recommendGoodsList != null ? recommendGoodsList : new ArrayList<GoodsIdsQueryVO>());
        result.setPcGoodsPage(pcGoodsPage != null ? pcGoodsPage : new ArrayList<WebSystemConfigQueryVO>());
        return ResponseResult.success( result);
    }

    @Override
    public ResponseResult getImageConfigUrl(String configKey) {
        if (configKey ==null || "".equals(configKey)){
            return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(), BizCodeEnume.KEY_VALUE_CANNOT_BE_EMPTY.getMsg());
        }
        String imageValue=baseSysConfigsMapper.getImageConfigUrl(configKey);

        return ResponseResult.success(imageValue);
    }

    /**
     * 获取商品分类所有的子分类
     *
     * @param allMenu
     * @param catId
     * @return
     */
    public List<WebCatMenuVO> getMenuList4(List<WebCatMenuVO> allMenu, Integer catId) {
        List<WebCatMenuVO> goodsCatsList = Lists.newArrayList();

        if (!org.springframework.util.CollectionUtils.isEmpty(allMenu)) {
            for (WebCatMenuVO catMenu : allMenu) {
                if (catMenu.getCatId().equals(catId)) {
                    goodsCatsList.add(catMenu);
                    if (!catMenu.getCatParentId().equals(0)) {
                        goodsCatsList = getChild4(allMenu, catMenu.getCatParentId(), goodsCatsList);
                    }
                    break;
                }

            }
        }
        return goodsCatsList;

    }

    /**
     * 找出子菜单
     * @param allMenu
     * @param parentId
     * @param goodsCatsList
     * @return
     */
    private List<WebCatMenuVO> getChild4(List<WebCatMenuVO> allMenu, Integer parentId, List<WebCatMenuVO> goodsCatsList) {

        for (WebCatMenuVO catMenu : allMenu) {
            if (catMenu.getCatId().equals(parentId)) {
                goodsCatsList.add(0,catMenu);
                parentId = catMenu.getCatParentId();
                if (!parentId.equals(0)) {
                    goodsCatsList = getChild4(allMenu, parentId, goodsCatsList);
                }
            }
        }

        return goodsCatsList;
    }

    @Override
    public ResponseResult queryFoodExhibitionHall() {
        WebFoodsHallIndexResultVO result = new WebFoodsHallIndexResultVO();

        // 查询首页
        List<WabSystemConfigHallVO> slides = baseSysConfigsMapper.selectByConfigType("foodSliderPC");
        // 地方特产馆
        WebSystemConfigQueryDTO param = new WebSystemConfigQueryDTO();
        List<WebIndexSpecialtysHallVO> halls = getSpeciatysHall(param);
        // 查询所有特产馆
        List<WapGoodsFoodExhibitionHallResultVO> foodHall = baseFoodExhibitionHallMapper.selectByAll();

        result.setAllHall(foodHall);
        result.setSlides(slides);
        result.setRecommendHall(halls);


        return ResponseResult.success(result);
    }

    @Override
    public ResponseResult foodExhibitionHallDetail(Integer exhibitionHallId) {
        WapGoodsFoodExhibitionHallVO hall = baseFoodExhibitionHallMapper.selectFoodExhibitionHallById(exhibitionHallId);
        if (null == hall ) {
            return ResponseResult.success();
        }
        List<String> goodsIdsStr = Arrays.asList(hall.getGoodsId().split(","));
        List<Integer> goodsIds = Lists.newArrayList();
        for (String goodsIdStr : goodsIdsStr) {
            goodsIds.add(Integer.parseInt(goodsIdStr));
        }
        List<WapHallGoodsQueryResultVO> commonList = this.webIndexMapper.selectByGoodsIds(goodsIds);
        hall.setCommonList(commonList);
        return ResponseResult.success(hall);
    }

    @Override
    public ResponseResult queryButtomHelp() {
        Map<String,Object> restultMap = new HashMap<>();
        // 查询所有的组
        List<WebIndexArticleGroupVO> articleGroups = baseArticleGroupMapper.selectAllGroup();
        String rr = baseSysConfigsMapper.selectBaseWebConfig(CommonType.configKey.WEB_COLOR.getDesc());
        restultMap.put("webColor",rr);
        for (WebIndexArticleGroupVO articleGroup : articleGroups) {
            List<WebArticleBaseNameVO> articletitle = baseArticleBaseMapper.selectByGroupId(articleGroup.getArticleGroupId(),
                    null);

            if (articletitle != null && articletitle.size() > 0) {
                for (WebArticleBaseNameVO webArticleBaseName2 : articletitle) {
                    if (StringUtils.isNotEmpty(webArticleBaseName2.getArticleUrl())) {
                        webArticleBaseName2.setArticleGroupId(3);
                    }
                }
            }
            articleGroup.setArticletitle2(articletitle);

        }
        restultMap.put("articleGroups",articleGroups);
        return ResponseResult.success(restultMap);
    }

    @Override
    public ResponseResult newQueryPcIndex(Map<String, Object> map) {
        //用于存放首页数据 排序后 返回前端
        List<GdbPcIndexVO> pcIndexData = new ArrayList<>();
        try {
            String pcIndexConfig2 = RedisPrefixUtils.pcIndexConfig;
            //会员折扣 - plus折扣
            String  memberDiscount = null;
            Integer  plusMember = null;
            if (map.get("token") != null && map.get("token") != ""){
                //用户登录
                String userId = null;
                String userInfoStr = RedisUtil.get(RedisConstants.FKGOU_USER_TOKEN_USER + map.get("token"));
                if(StrUtil.isNotEmpty(userInfoStr)){
                    UserInfoVO userInfo = ParseTokenUtils.getUserInfoByToken(map.get("token").toString());
                    if (userInfo != null) {
                        userId = userInfo.getUserId();
                        memberDiscount = String.valueOf(userInfo.getPlusDiscount());
                        plusMember = userInfo.getPlusMember();
                    }
                }
                pcIndexConfig2 = pcIndexConfig2 + "_" + userId;

            }
            String pcConfig = RedisUtil.get(pcIndexConfig2);
            if(StrUtil.isNotBlank(pcConfig)){
                pcIndexData = JSON.parseObject(pcConfig, new TypeReference<List<GdbPcIndexVO>>() {});//从redis中获取
                return ResponseResult.success(pcIndexData);
            }
            //查询 gdb_pc_index_config 数据 pageType 1 天天特价 2 特色专题  3 为你推荐 4家居馆
            Map<Integer, List<PcConfigResultVO>> pcConfigResults = basePcIndexConfigService.querygdbPcIndexConfig();
            //便利结果集 封装数据
            if(null != pcConfigResults){
                for (Map.Entry<Integer, List<PcConfigResultVO>> entry : pcConfigResults.entrySet()) {
                    //存储数据
                    GdbPcIndexVO gdbPcIndexDTO = new GdbPcIndexVO();
                    List<PcConfigResultVO> pcConfigResultList = new ArrayList<>();
                    pcConfigResultList = entry.getValue();
                    //设置会员折扣
                    if (memberDiscount != null && memberDiscount != "null") {
                        gdbPcIndexDTO.setMemberDiscount(memberDiscount);
                    }
                    //设置plus会员
                    gdbPcIndexDTO.setPlusMember(plusMember);
                    //获取模块数据
                    gdbPcIndexDTO.setData(pcConfigResultList);
                    //获取模块类型
                    gdbPcIndexDTO.setPageType(pcConfigResultList.stream().map(PcConfigResultVO::getPageType).collect(Collectors.toList()).get(0));
                    //获取模块排序
                    gdbPcIndexDTO.setPageSort(pcConfigResultList.stream().map(PcConfigResultVO::getPageSort).collect(Collectors.toList()).get(0));
                    pcIndexData.add(gdbPcIndexDTO);
                }
            }
            //查询 gdb_merchant_floor_adpage  5 单楼层 6 多楼层
            Map<Integer, List<MerchantFloorAdpageVO>> integerListMap = queryGdbMerchantFloorAdpage();
            for (Map.Entry<Integer, List<MerchantFloorAdpageVO>> entry : integerListMap.entrySet()) {
                List<MerchantFloorAdpageVO> gdbMerchantFloorAdpageList = new ArrayList<>();
                gdbMerchantFloorAdpageList = entry.getValue();
                // 单楼层数据遍历存入
                if (5 == entry.getKey()) {
                    for (MerchantFloorAdpageVO gdbMerchantFloorAdpage : gdbMerchantFloorAdpageList) {
                        //存储数据
                        GdbPcIndexVO gdbPcIndexDTO = new GdbPcIndexVO();
                        //设置会员折扣
                        if (memberDiscount != null && memberDiscount != "null") {
                            gdbPcIndexDTO.setMemberDiscount(memberDiscount);
                        }
                        //设置plus会员
                        gdbPcIndexDTO.setPlusMember(plusMember);
                        //获取模块数据
                        gdbPcIndexDTO.setData(Lists.newArrayList(gdbMerchantFloorAdpage));
                        //获取模块类型
                        gdbPcIndexDTO.setPageType(gdbMerchantFloorAdpage.getPageType());
                        //获取模块排序
                        gdbPcIndexDTO.setPageSort(gdbMerchantFloorAdpage.getFloorAdpageOrder());
                        //单楼层数据需存入楼层id
                        gdbPcIndexDTO.setFloorAdpageId(gdbMerchantFloorAdpage.getFloorAdpageId());
                        pcIndexData.add(gdbPcIndexDTO);
                    }
                } else {
                    //存储数据
                    GdbPcIndexVO gdbPcIndexDTO = new GdbPcIndexVO();
                    //设置会员折扣
                    gdbPcIndexDTO.setMemberDiscount(memberDiscount);
                    //设置plus会员
                    gdbPcIndexDTO.setPlusMember(plusMember);
                    //6 多楼层数据 一个list返回
                    //获取模块数据
                    gdbPcIndexDTO.setData(gdbMerchantFloorAdpageList);
                    //获取模块类型
                    gdbPcIndexDTO.setPageType(gdbMerchantFloorAdpageList.stream().map(MerchantFloorAdpageVO::getPageType).collect(Collectors.toList()).get(0));
                    //获取模块排序
                    gdbPcIndexDTO.setPageSort(gdbMerchantFloorAdpageList.stream().map(MerchantFloorAdpageVO::getFloorAdpageOrder).collect(Collectors.toList()).get(0));
                    pcIndexData.add(gdbPcIndexDTO);
                }
            }
            List<GdbPcIndexVO> collect = pcIndexData.stream().sorted(Comparator.comparing(GdbPcIndexVO::getPageSort)).collect(Collectors.toList());
            RedisUtil.set(pcIndexConfig2, JSONSerializer.serialize(collect), 60 * 60 * 24);//存入redis
            return ResponseResult.success(collect);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseResult.fail(BizCodeEnume.SYSTEM_ERROR.getCode(),BizCodeEnume.SYSTEM_ERROR.getMsg());
    }

    @Override
    public ResponseResult queryAllSupplyAdpageFloor() {
        List<BaseFloorAdpageEntity> entityList = baseFloorAdpageMapper.selectList(new LambdaQueryWrapper<BaseFloorAdpageEntity>()
                .eq(BaseFloorAdpageEntity::getFloorType, CommonType.storeType.SUPPLIER_STORE.getCode()));


        /**
         * 封装数据
         */
        List<MerchantFloorAdpageVO> allFloorAdpages = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(entityList)) {
            allFloorAdpages = entityList.stream().map(entity -> {
                MerchantFloorAdpageVO catResult = new MerchantFloorAdpageVO();

                BeanUtils.copyProperties(entity, catResult);
                return catResult;
            }).collect(Collectors.toList());
        }
        List<WebCatMenuVO> allMenu = null;
        for (MerchantFloorAdpageVO allFloorAdpage : allFloorAdpages) {
            // 获取楼层名称
            WebFloorAdpageNameDTO floorAdpageNameNew = JsonUtils.string2Obj(allFloorAdpage.getFloorAdpageName(),
                    WebFloorAdpageNameDTO.class);
            allFloorAdpage.setFloorAdpageNameNew(floorAdpageNameNew);
            // 获取轮播图
            List<Integer> goodsIdList2 = JsonUtils.StringToList2(allFloorAdpage.getLeftAdpageBanner());
            List<GoodsIdsQueryListVO> adpageBannerList = baseFloorAdpageMapper.selectByGoodIds2(goodsIdList2);
            allFloorAdpage.setAdpageBannerList(adpageBannerList);
            // 获取左侧广告
            List<PlatformLeftAdpageNavDTO> leftAdpageNavList = JsonUtils.string2Obj(allFloorAdpage.getLeftAdpageNav(),
                    List.class, PlatformLeftAdpageNavDTO.class);
            allFloorAdpage.setLeftAdpageNavList(leftAdpageNavList);
            // 获取右侧热门推荐
            PlatformRightAdpageNavDTO rightRec = JsonUtils.string2Obj(allFloorAdpage.getRightHotRecommend(),
                    PlatformRightAdpageNavDTO.class);
            allFloorAdpage.setRightRec(rightRec);

            if (StringUtils.isNotEmpty(rightRec.getRightAdpageNavGoodsId())) {
                List<Integer> rightAdpageNavGoodsIds = JsonUtils.StringToList2(rightRec.getRightAdpageNavGoodsId());


                List<GoodsIdsVO> rightRecGoodsList = new ArrayList<>();
                MobConfigGoodsDTO query = new MobConfigGoodsDTO();

                // 获取所有的子分类
                if (null == allMenu) {
                    allMenu = baseFloorAdpageMapper.selectAllCat2();
                }
                List<Integer> catIds = getMenuList(allMenu, floorAdpageNameNew.getCatId());
                query.setCatIds(catIds);
                query.setGoodsIdList(rightAdpageNavGoodsIds);
                query.setGoodsNum(8 - rightRecGoodsList.size());
                System.out.println("query===>" + query.getGoodsIdList());
                List<Integer> goodsVarList = query.getGoodsIdList();
                for (Integer goodsId : goodsVarList) {
                    System.out.println("var===>" + goodsId);
                    System.out.println("var===>" + goodsId.getClass());

                    GoodsIdsVO param = baseFloorAdpageMapper.newSelectWebFloorMobConfig(goodsId);
                    if (param != null) {
                        rightRecGoodsList.add(param);
                    }

                }


                allFloorAdpage.setRightRecGoodsList(rightRecGoodsList);
            }
            // 获取右侧分类广告
            allFloorAdpage.setRightAdpageNavList(JsonUtils.string2Obj(allFloorAdpage.getRightAdpageNav(), List.class,
                    WebFloorAdpageNameDTO.class));

        }
        return ResponseResult.success(allFloorAdpages);
    }

    @Override
    public ResponseResult pcIndexFloorUpdate(Map<String, Object> map) {
        //  楼层 id
        Integer floorAdpageId = Integer.valueOf(map.get("floorAdpageId").toString());
        //  1 开启 2 关闭
        Integer floorStatus = Integer.valueOf(map.get("floorStatus").toString());
        baseFloorAdpageMapper.pcIndexFloorUpdate(floorAdpageId, floorStatus);
        //删除redis缓存
        RedisUtil.removeAll(RedisPrefixUtils.pcIndexConfig);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult pcIndexConfigUpdate(Map<String, Object> map) {
        // 1 天天特价 2 特色专题  3 为你推荐 4 楼层
        Integer pageType = Integer.valueOf(map.get("pageType").toString());
        //  1 开启 2 关闭
        Integer pageStart = Integer.valueOf(map.get("pageStart").toString());

        baseFloorAdpageMapper.pcIndexConfigUpdate(pageType, pageStart);
        //删除redis缓存
        RedisUtil.removeAll(RedisPrefixUtils.pcIndexConfig);
        return ResponseResult.success();
    }


    public Map<Integer, List<MerchantFloorAdpageVO>> queryGdbMerchantFloorAdpage(){

        List<BaseFloorAdpageEntity> entityList = baseFloorAdpageMapper.selectList(new LambdaQueryWrapper<BaseFloorAdpageEntity>()
                .eq(BaseFloorAdpageEntity::getFloorType, CommonType.storeType.SELLER_STORE.getCode()));
        /**
         * 封装数据
         */
        List<MerchantFloorAdpageVO> allFloorAdpages = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(entityList)) {
            allFloorAdpages = entityList.stream().map(entity -> {
                MerchantFloorAdpageVO catResult = new MerchantFloorAdpageVO();

                BeanUtils.copyProperties(entity, catResult);
                return catResult;
            }).collect(Collectors.toList());
        }

        for (MerchantFloorAdpageVO allFloorAdpage : allFloorAdpages) {
            // 获取楼层名称
            WebFloorAdpageNameDTO floorAdpageNameNew = JsonUtils.string2Obj(allFloorAdpage.getFloorAdpageName(),
                    WebFloorAdpageNameDTO.class);
            allFloorAdpage.setFloorAdpageNameNew(floorAdpageNameNew);
            // 获取轮播图
            List<Integer> goodsIdList2 = JsonUtils.StringToList2(allFloorAdpage.getLeftAdpageBanner());
            List<GoodsIdsQueryListVO> adpageBannerList = webIndexMapper.selectByGoodIds(goodsIdList2);
            allFloorAdpage.setAdpageBannerList(adpageBannerList);
            // 获取左侧广告
            List<PlatformLeftAdpageNavDTO> leftAdpageNavList = JsonUtils.string2Obj(allFloorAdpage.getLeftAdpageNav(),
                    List.class, PlatformLeftAdpageNavDTO.class);
            for (PlatformLeftAdpageNavDTO platformLeftAdpageNav : leftAdpageNavList) {
                String leftAdpageNavUrl = String.valueOf(platformLeftAdpageNav.getLeftAdpageNavUrl());
                if (StringUtils.isNotEmpty(leftAdpageNavUrl)) {
                    Map urlMap = JSON.parseObject(leftAdpageNavUrl, Map.class);
                    if (platformLeftAdpageNav.getOpType() != null) {
                        //封装商品信息
                        if (platformLeftAdpageNav.getOpType().equals(2) && null != urlMap.get("commonId")) {
                            String commonId = String.valueOf(urlMap.get("commonId"));
                            if (StringUtils.isNotEmpty(commonId)) {
                                String commonName = webIndexMapper.selectCommonNameId(Integer.valueOf(commonId));
                                platformLeftAdpageNav.setCommonName(commonName);
                            }
                            //封装店铺信息
                        } else if (platformLeftAdpageNav.getOpType().equals(4) && null != urlMap.get("shopId")) {
                            String shopId = String.valueOf(urlMap.get("shopId"));
                            if (StringUtils.isNotEmpty(shopId)) {
                                String shopName = webIndexMapper.selectByShopNameId(Integer.valueOf(shopId));
                                platformLeftAdpageNav.setShopName(shopName);
                            }
                            //封装分类信息
                        } else if (platformLeftAdpageNav.getOpType().equals(6) && null != urlMap.get("catId")) {
                            String catId = String.valueOf(urlMap.get("catId"));
                            if (StringUtils.isNotEmpty(catId)) {
                                String catName = webIndexMapper.selectByCatNameString(Integer.valueOf(catId));
                                platformLeftAdpageNav.setCatName(catName);
                            }
                        }
                    }
                }
            }
            allFloorAdpage.setLeftAdpageNavList(leftAdpageNavList);
            // 获取右侧热门推荐
            PlatformRightAdpageNavDTO rightRec = JsonUtils.string2Obj(allFloorAdpage.getRightHotRecommend(),
                    PlatformRightAdpageNavDTO.class);
            allFloorAdpage.setRightRec(rightRec);
            // 设置的商品数量
            if(StringUtils.isNotEmpty(rightRec.getRightAdpageNavGoodsId())) {
                List<Integer> rightAdpageNavGoodsIds = JsonUtils.StringToList2(rightRec.getRightAdpageNavGoodsId());

                List<GoodsIdsVO> rightRecGoodsList = new ArrayList<>();
                MobConfigGoodsVO query = new MobConfigGoodsVO();
                List<WebCatMenuVO> allMenu = null;
                // 获取所有的子分类
                if (null == allMenu) {
                    allMenu = webIndexMapper.selectAllCat2();
                }
                List<Integer> catIds = getMenuList(allMenu, floorAdpageNameNew.getCatId());
                query.setCatIds(catIds);
                query.setGoodsIdList(rightAdpageNavGoodsIds);
                query.setGoodsNum(8 - rightRecGoodsList.size());
                List<Integer> goodsVarList =query.getGoodsIdList();
                for (Integer goodsId :goodsVarList){
                    GoodsIdsVO param = webIndexMapper.newSelectWebFloorMobConfig(goodsId);
                    if (param !=null){
                        rightRecGoodsList.add(param);
                    }
                }
                allFloorAdpage.setRightRecGoodsList(rightRecGoodsList);
            }
            // 获取右侧分类广告
            allFloorAdpage.setRightAdpageNavList(JsonUtils.string2Obj(allFloorAdpage.getRightAdpageNav(), List.class,
                    WebFloorAdpageNameVO.class));
        }
        //对数据库中数据分组 返回
        Map<Integer, List<MerchantFloorAdpageVO>> collect = allFloorAdpages.stream().collect(Collectors.groupingBy(MerchantFloorAdpageVO::getPageType));
        return collect;
    }
}
